﻿using CNKI.TPI.Web.Base;
using CNKI.TPI.Web.Interface.Models;
using CNKI.TPI.Web.Report.IBLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace CNKI.TPI.Web.Interface.Areas.Log.Controllers
{
    public class GetDBStatisticsInfoController : BaseApiController
    {
        private IDBStatisticsService dbStatisticsService = null;

        public GetDBStatisticsInfoController(IDBStatisticsService dbStatisticsService)
        {
            this.dbStatisticsService = dbStatisticsService;
        }

        // GET api/userrecommend/5
        public object Get(string clsCode, string dBName, string startDate, string endDate, int pageIndex, int pageSize)
        {
            OutputEntityExt result = new OutputEntityExt();
            try
            {
                DateTime? start = null;
                DateTime? end = null;
                if (!string.IsNullOrEmpty(startDate))
                {
                    start = DateTime.Parse(startDate);
                }
                if (!string.IsNullOrEmpty(endDate))
                {
                    end = DateTime.Parse(endDate);
                }
                DataTable dt = dbStatisticsService.GetDBStatisticsInfo(start, end, clsCode, dBName);
                if (dt == null)
                {
                    result.Status = Status.Error;
                }
                else
                {
                    result.Status = Status.Success;
                    result.DataCount = dt.Rows.Count;
                    result.data = DataTableHelper.SplitDataTable(dt, pageIndex, pageSize);
                }
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
                result.Status = Status.Error;
                result.message = ex.Message;
            }
            return result;
        }
    }
}
